package Test2;

import java.util.LinkedList;
import java.util.Queue;

public class Test1 {
}
class MyStack {
    Queue<Integer> queue1;
    //构造
    public MyStack() {
        queue1=new LinkedList<>();
    }
    //用队列实现栈
    //栈顶插入
    public void push(int x) {
        queue1.add(x);
    }
    public int pop() {
        int p=queue1.size();
        while (p>1) {
            queue1.add(queue1.poll());
            p--;
        }
        return queue1.poll();
    }

    public int top() {

        int p=queue1.size();
        while (p>1) {
            queue1.add(queue1.poll());
            p--;
        }
        int c=queue1.peek();
        queue1.add(queue1.poll());
        return c;
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}